package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.Review;
import com.shop.result.ResultVO;
import com.shop.service.ReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/review")
public class ReviewController extends BaseController {

    private final ReviewService reviewService;

    /**
     * 获取所有评价
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listReview")
    public PageInfo<Review> listReview(Integer pageNum, Integer pageSize) {
        return reviewService.listReview(pageNum, pageSize);
    }

    /**
     * 获取评价
     * @param id
     * @return
     */
    @GetMapping("/getReviewById")
    public List<Review> getReviewById(@RequestParam("id")Integer id) {
        return reviewService.getReviewById(id);
    }

    /**
     * 添加评价
     * @param review
     */
    @PostMapping("/addReview")
    public ResultVO<Review> addReview(@RequestBody Review review) {
        reviewService.addReview(review);
        return success(review);
    }

    /**
     * 修改评价
     * @param review
     */
    @GetMapping("/updateReview")
    public void updateReview(Review review) {
        reviewService.updateReview(review);
    }

    /**
     * 删除评价
     * @param id
     */
    @GetMapping("/deleteReview")
    public void deleteReview(Integer id) {
        reviewService.deleteReview(id);
    }
}
